﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Base;
using UserInfo;

public partial class login_FindPwd : Base.BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
  
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (txtName.Text.Trim() == "")
        {
            lblSuc.Text = "必须填写用户登录名 ";
        }
        if (txtNewPwd.Text.Trim() == "")
        {
            lblSuc.Text = "请输入密码！";
            return;
        }
        if (txtReNewPwd.Text.Trim() == "")
        {
            lblSuc.Text = "请输入确认密码！";
            return;
        }
        else
        {
            bool flag = Base.Common.isPassPwd(txtNewPwd.Text.Trim());
            if (!flag)
            {
                lblSuc.Text = "密码只能用英文字母、数字、下划线组成的6-20个字符!";
                return;
            }
            if (txtReNewPwd.Text.Trim() != txtNewPwd.Text.Trim())
            {
                lblSuc.Text = "两次输入的密码不一致!";
                return;
            }
            if (Request.QueryString["UserID"] != null && Request.QueryString["UserID"] != "")
            {  
                string UserID =Request.QueryString["UserID"].ToString();
                string where="where UserID="+UserID;
                IUserInfo user = new RUserInfo();
                DataTable dt=user.GetDataTable(where);
                string name = dt.Rows[0]["LoginName"].ToString();
                if (name == txtName.Text.Trim())
                {
                    string Md5Pawd = Common.Encryption(txtNewPwd.Text.Trim());
                    user.FindUpdatePwd(int.Parse(UserID), Md5Pawd);
                    ShowMessage("密码修改成功！", "/login/login.aspx");
                }
                else
                    lblSuc.Text = "请确保您输入的会员登陆名和您收到该链接的邮箱相符合！";
            }
            else
            {
                string strLogName = Base.GetRequest.Filter(txtName.Text.Trim().Replace("'", ""));
                string where = "where LoginName='" + strLogName + "'";
                IUserInfo user = new RUserInfo();
                DataTable dt = user.GetDataTable(where);
                if (dt.Rows.Count == 0)
                {
                    dt.Clear();
                    dt.Dispose();
                    lblSuc.Text = "用户名不存在！";
                    return;
                }
                else
                {
                    string UserId = dt.Rows[0]["UserID"].ToString();
                    string Md5Pawd = Common.Encryption(txtNewPwd.Text.Trim());
                    dt.Clear();
                    dt.Dispose();
                    user.FindUpdatePwd(int.Parse(UserId), Md5Pawd);
                    ShowMessage("密码修改成功！", "/login/login.aspx");
                }
            }
        }
    }
}
